//
//  WBBaseController.swift
//  WBTest
//
//  Created by pengZY on 2017/9/25.
//  Copyright © 2017年 zhang. All rights reserved.
//

import UIKit

class WBBaseController: UIViewController,UITableViewDataSource,UITableViewDelegate {
       let table = UITableView.init(frame: UIScreen.main.bounds, style: .plain)
    
    var refreshController:UIRefreshControl = UIRefreshControl.init()
    //判断是否是tableview
    var isTable : Bool = false{
        willSet{
            if newValue == true {
                self.view.addSubview(table)
                table.delegate = self
                table.dataSource = self
                table.register(UITableViewCell.self, forCellReuseIdentifier: "ad")
                table.backgroundColor = UIColor.gray
            }
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.navigationBar.titleTextAttributes  = [NSForegroundColorAttributeName:UIColor.red,NSFontAttributeName:UIFont.systemFont(ofSize: 16.0)]
        
        table.addSubview(refreshController)
        self.refreshController.addTarget(self, action: #selector(refreshData), for: .valueChanged)
        
             setUIView()
    }
    func refreshData() {
        
            refreshController.endRefreshing()
          }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ad", for: indexPath)
        
        return cell
    }

}


extension WBBaseController{
    func setUIView()->(){
        self.view.backgroundColor = UIColor.init(colorLiteralRed:Float(CGFloat(arc4random_uniform(255))/255.0), green: Float(CGFloat(arc4random_uniform(255))/255.0), blue: Float(CGFloat(arc4random_uniform(255))/255.0), alpha: 1.0)
    }
    
    
}
